package com.example.springboot.util;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.http.HttpStatus;

import java.util.HashMap;
import java.util.Map;

/**
 * 定义返回格式
 * @default
**/
@AllArgsConstructor
@Data
public class R {

    private String msg;

    private Integer code;

    private Map<String,Object> data = new HashMap<>();

    public static R ok(){
        return new R("成功", HttpStatus.OK.value(), null);
    }

    public static R ok(Map<String,Object> data){
        return new R("成功", HttpStatus.OK.value(), data);
    }

    public static R error(){
        return new R("失败", HttpStatus.INTERNAL_SERVER_ERROR.value(), null);
    }

    public static R error(String msg){
        return new R(msg, HttpStatus.INTERNAL_SERVER_ERROR.value(), null);
    }

    public static R err_401(){
        return new R("未授权", HttpStatus.UNAUTHORIZED.value(), null);
    }
}
